package testing;

import com.libfintech.verification.service.ISmsService;
import com.libfintech.verification.service.Result;
import com.libfintech.verification.service.impl.DaYuConfig;
import com.libfintech.verification.util.VerificationUtil;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class DaYuTesting {
    private static final ISmsService SMS_SERVICE;
    static {
        DaYuConfig config = new DaYuConfig();
        //大鱼提供的url/apikey/secret
        config.setServerUrl("http://gw.api.taobao.com/router/rest");
        config.setAppKey("23359005");
        config.setAppSecret("3c10f7403365798436848ba1ecd5702e");
        //不设置仓储配置表示本地仓储（缓存）
//        config.setRepositoryConfig(null);


//        //redis仓储配置
//        RedisRepositoryConfig repositoryConfig = new RedisRepositoryConfig();
//        //redis所在主机ip和端口
//        repositoryConfig.setHost("");
//        //redis密码，若无密码时，不需要配置
//        repositoryConfig.setPass("");
//        //redis数据库，不建议修改默认值
//        repositoryConfig.setDb(2);
//        config.setRepositoryConfig(repositoryConfig);


        SMS_SERVICE = VerificationUtil.createSmsService(config);
    }
    /**
     * 测试发送验证码
     */
    @Test
    public void testSending() {
        Map<String, Object> smsParams = new HashMap<String, Object>();
        smsParams.put("extend", "");
        smsParams.put("smsType","normal");
        // 可多个群发，用短信接收号码。支持单个或多个手机号码，传入号码为11位手机号码，不能加0或+86。
        // 群发短信需传入多个号码，以英文逗号分隔，一次调用最多传入200个号码。示例：18600000000,13911111111,13322222222
        smsParams.put("recNum","13704755857");
        smsParams.put("smsTemplateCode","SMS_11041284");
        smsParams.put("smsFreeSignName","精彩美课");
        smsParams.put("smsParamString", "{name:'王鑫'}");
        Result<String> result = SMS_SERVICE.sendNotification(smsParams,"wonderfullclass");

        System.out.println(result.getErrorMsg());
        System.out.println(result.getData());
    }

    @Test
    public void testGetRandomCode(){
        for (int i = 0; i < 10; i++) {
            System.out.println(SMS_SERVICE.getRandomCode(6));
        }
    }
}

